package com.rtwo.shiro.config;

import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Created by hasee on 2017/6/1.
 */
@Configuration
public class ShiroConfig {

    @Bean
    public SecurityManager MySecurityManager(){
        DefaultWebSecurityManager defaultSecurityManager = new DefaultWebSecurityManager();
        return defaultSecurityManager;
    }

    @Bean
    public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager){
        System.out.println("ShiroConfiguration.shirFilter()");
        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        shiroFilterFactoryBean.setSecurityManager(securityManager);
        Map<String,String> filterChain = new LinkedHashMap<>();
        filterChain.put("/logout","logout");
//        filterChain.put("/**","authc");
        shiroFilterFactoryBean.setLoginUrl("/shiro/");
        shiroFilterFactoryBean.setSuccessUrl("/shiro/home");
        shiroFilterFactoryBean.setUnauthorizedUrl("/shiro/403");
        shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChain);
        return shiroFilterFactoryBean;
    }


}
